package com.example.attendance_back.controller;


import com.example.attendance_back.model.ResponseMessage;
import com.example.attendance_back.model.StudentSign;
import com.example.attendance_back.service.StudentSignService;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.relational.core.sql.In;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.Locale;

@RestController
@RequestMapping("/ssign")
@CrossOrigin
public class StudentSignController {

    @Autowired
    private StudentSignService service;

    @PostMapping("/sign")
    public ResponseMessage signIn(Integer studentSignId,
                        String sign_time) throws ParseException {
        System.out.println(sign_time);

        SimpleDateFormat formatter = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss"
                , Locale.CHINESE);

        Date date = formatter.parse(sign_time);

        

        return service.signIn(studentSignId,date);
    }


    @GetMapping("/bystuid")
    public ResponseMessage getListByStudentId(Integer studentId){

        return service.getStuSignsByStudentId(studentId);
    }

    @GetMapping("/byteacherid")
    public ResponseMessage getListByTeacherId(Integer teacherId){

        return service.getStuSignsByTeacherId(teacherId);
    }


    @PostMapping("/save")
    public ResponseMessage save(StudentSign studentSign){
        return  service.save(studentSign);
    }
}
